package com.fcscs.cservice.domain.validator;

import com.fcscs.core.common.ErrorEnums;
import com.fcscs.core.common.FieldValidators;
import com.fcscs.core.domain.validator.BaseValidator;
import com.fcscs.cservice.common.CServiceCommonEnums.InRoomCategoryLevel;
import com.fcscs.cservice.common.CServiceCommonUtils;
import com.fcscs.cservice.domain.InRoomCategory;
import com.fcscs.cservice.domain.InRoomItem;
import com.fcscs.cservice.domain.InRoomItemPrice;
import com.fcscs.cservice.domain.InRoomMenu;

public interface ECMSInRoomMenuValidators {

	public static class InRoomItemValidator extends BaseValidator<InRoomItem> {
		public ErrorEnums validate(InRoomItem entity, boolean newInstance) {
			ErrorEnums err = super.validate(entity, newInstance);
			if (err != null) {
				return err;
			} else {
				if (FieldValidators.isNullEmptyStr(entity.getName())
						|| FieldValidators.isNullEmptyStr(entity.getDescription())
						|| entity.getTransactionTypeId() == null || entity.getChargeCategoryId() == null
						|| entity.getLeadTime() == null) {
					return ErrorEnums.GeneralError.REQURIED_FLD_MISSING;
				}
			}
			return null;
		}
	}

	public static class InRoomPriceValidator extends BaseValidator<InRoomItemPrice> {
		public ErrorEnums validate(InRoomItemPrice entity, boolean newInstance) {
			ErrorEnums err = super.validate(entity, newInstance);
			if (err != null) {
				return err;
			} else {
				if (entity.getPriceCategoryEnum() == null || entity.getPrice() == null) {
					return ErrorEnums.GeneralError.REQURIED_FLD_MISSING;
				} else if (newInstance == false && entity.getItemId() < 1) {
					return ErrorEnums.GeneralError.REQURIED_FLD_MISSING;
				}
			}
			return null;
		}
	}

	public static class InRoomCategoryValidator extends BaseValidator<InRoomCategory> {
		
		public ErrorEnums validate(InRoomCategory entity, boolean newInstance) {
			ErrorEnums err = super.validate(entity, newInstance);
			if (err != null) {
				return err;
			} else {
				if (FieldValidators.isNullEmptyStr(entity.getName())
						|| FieldValidators.isNullEmptyStr(entity.getDescription()) || entity.getLevel() == null
						|| entity.getPriceCategoryEnum() == null) {
					return ErrorEnums.GeneralError.REQURIED_FLD_MISSING;
				} else if (InRoomCategoryLevel.levels().contains(entity.getLevel()) == false) {
					return ErrorEnums.GeneralError.WRONG_LOV_TYPE;
				}
			}
			return null;
		}
		
	}

	public static class InRoomMenuValidator extends BaseValidator<InRoomMenu> {
		public ErrorEnums validate(InRoomMenu entity, boolean newInstance) {
			ErrorEnums err = super.validate(entity, newInstance);
			if (err != null) {
				return err;
			} else {
				if (entity.getCategoryId() < 1) {
					return ErrorEnums.GeneralError.REQURIED_FLD_MISSING;
				} else if (CServiceCommonUtils.isNullOrNegative(entity.getSubcategoryId())
						&& (CServiceCommonUtils.isNullOrNegative(entity.getItemId()) == false || CServiceCommonUtils
								.isNullOrNegative(entity.getAutoSuggestionItemId()) == false)) {
					return ErrorEnums.GeneralError.REQURIED_FLD_MISSING;
				} else if (CServiceCommonUtils.isNullOrNegative(entity.getItemId())
						&& CServiceCommonUtils.isNullOrNegative(entity.getAutoSuggestionItemId()) == false) {
					return ErrorEnums.GeneralError.REQURIED_FLD_MISSING;
				}
			}
			return null;
		}
	}

}
